

$(document).ready(function() {
/*			главный слайдер				*/

			$(function() {
				var left = {				
					h2			: -500,
					span		: -500,
					a			: -500
				}
				var current = {				
					h2			: 6,
					span		: 6,
					a			: 0
				}
				var right = {					
					h2			: 990,
					span		: 990,
					a			: 990
				}
			
				var isScrolling = false;
				$('#carousel').carouFredSel({
					
					scroll	: {			
						fx: 'scroll',
						duration		: 500,
						timeoutDuration	: 0
						
											
						
					},
					auto	: false,
					prev	: {
						button		: '.prev',
						onBefore	: function( data ) {

					$('.carou-text').find('h2').addClass('.ie-opacity').animate({opacity:0},110);
						$('.carou-text').find('span').addClass('.ie-opacity').animate({opacity:0},110);
						$('.carou-text').find('a').addClass('.ie-opacity').animate({opacity:0},110);
							
							/*data.items.old.find('h2')
								.delay(0)
								.animate({
									left: right.h2, opacity:0
								});

							data.items.old.find('span')
								.delay(0)
								.animate({
									left: right.span, opacity:0
								});

							data.items.old.find('a')
								.delay(0)
								.animate({
									 opacity:0
								});*/
						},
						onAfter: function( data ) {
						

							data.items.old.find('h2')
								.animate({
									left: current.h2
								});

							data.items.old.find('span')
								.css({
									left: current.span
								});

							

						

							data.items.visible.find('h2')
								.css({
									left: left.h2
								}).delay(100)
								.animate({
									left: current.h2, opacity:1
								},function() {
									isScrolling = false;
								});

							data.items.visible.find('span')
								.css({
									left: left.span
								}).delay(200)
								.animate({
									left: current.span, opacity:1
								});

							data.items.visible.find('a')
								.delay(450)
								.animate({
									 opacity:1
								});
						}
					},
					next	: {
						button		: '.next',

						onBefore	: function( data ) {

						$('.carou-text').find('h2').addClass('.ie-opacity').animate({opacity:0},110);
						$('.carou-text').find('span').addClass('.ie-opacity').animate({opacity:0},110);
						$('.carou-text').find('a').addClass('.ie-opacity').animate({opacity:0},110);
						
							/*data.items.old.find('h2')
								.delay(80)
								.animate({
									left: left.h2, opacity:0
								});

							data.items.old.find('span')
								.delay(1)
								.animate({
									left: left.span, opacity:0
								});

							data.items.old.find('a')
								.delay(50)
								.animate({
									 opacity:0 
								},100);*/
						},
						onAfter: function( data ) {
							
							data.items.old.find('h2')
								.animate({
									left: current.h2
								});

							data.items.old.find('span')
								.css({
									left: current.span
								});

						

						

							data.items.visible.find('h2')
								.css({
									left: right.h2
								}).delay(100)
								.animate({
									left: current.h2, opacity:1
								});

							data.items.visible.find('span')
								.css({
									left: right.span
								}).delay(200)
								.animate({
									left: current.span, opacity:1
								});

							data.items.visible.find('a')
								.delay(650)
								.animate({
									 opacity:1
								});
						}
					}
				});
			});
		
	
	$('.shop').carouFredSel({						
					prev: '.shop-back',					
					next: '.shop-forward',
					items: 4,					
					auto: false,
					scroll:{
						items:1,
						duration: 800
						
					}
	});

    /*$('.thanks-gallery ul').carouFredSel({
					prev: '.back',					
					next: '.forward',
					items: 4,

					auto: false,					
					scroll:{
						items:1,
						duration: 800
						
					}
	});*/
	
	$(".robot").fancybox({autoCenter: false});
	$(".form2").fancybox({autoCenter: false});
    $(".form").fancybox({autoCenter: false});
	
/*		стилизация формы		*/
	/*(function($) {
		$(function() {  
			$('input, select').styler();  
		})  
	})(jQuery)*/

    $('input, select').styler();

    /*		обратный счётчик		*/
	 //var myTime = $('.my-data').text();

    /*$('.count').each(function (i){

        var myTime = $(this).closest('.counter').find('.my-data').text();

        $(this).countdown({
            image: 'assets/images/digit-md.png',
            startTime: myTime,
            stepTime: 60,
            format: 'dd:hh:mm:ss',
            digitImages: 6,
            digitWidth: 36,
            digitHeight: 52
        });

    });*/

    /*-----Счетчик отбратного отсчета-----*/
    function parseDate(date){
        return Math.round(new Date(date.replace(/^(\d+)\.(\d+)\.(\d+)/, '$3-$2-$1')).getTime()/1000);
    }
    var new_date = $('.my-data').text();

    if ($('.count').length){
        $('.count').flipcountdown({

            tick:function(){
                var nol = function(h){
                    return h>9?h:'0'+h;
                }
                var    range     = parseDate(new_date)-Math.round((new Date()).getTime()/1000),
                    secday = 86400, sechour = 3600,
                    days     = parseInt(range/secday),
                    hours    = parseInt((range%secday)/sechour),
                    min        = parseInt(((range%secday)%sechour)/60),
                    sec        = ((range%secday)%sechour)%60;
                if (range < 0){
                    return nol(0)+' '+nol(0)+' '+nol(0)+' '+nol(0);
                }else{
                    return nol(days)+' '+nol(hours)+' '+nol(min)+' '+nol(sec);
                }
            }
        });
    }



    /*$('.count').countdown({
        image: 'assets/images/digit-md.png',
        startTime: myTime,
        stepTime: 60,
        format: 'dd:hh:mm:ss',
        digitImages: 6,
        digitWidth: 36,
        digitHeight: 52
    });*/
		
		/*var myTime2 = $('.my-data2').text();
		  $('#count2').countdown({
          image: 'assets/images/digit-md.png',
          startTime: myTime2,
		  stepTime: 60,
		format: 'dd:hh:mm:ss',		
		digitImages: 6,
		digitWidth: 36,
		digitHeight: 52
        });*/
      
	
	
	$(".photo-block a").fancybox({
    	openEffect	: 'elastic',
    	closeEffect	: 'elastic',
		prevEffect		: 'none',
		nextEffect		: 'none',
		centerOnScroll: 'false',
		showNavArrows: 'true',
		arrows: 'true',	
		scrolling:'yes',
    	tpl: {
			closeBtn : '<a title="Close" class="fancybox-item fancybox-close gallery-close" href="javascript:;"></a>',
		},
		helpers : {		
    		title : {
    			type : 'inside'
    		},
			overlay : {
				css : {
					'background' : 'rgba(58, 42, 45, 0.30)'
				}
			}
    	}
		});
		
		$(".thanks-gallery li a").fancybox({
    	openEffect	: 'elastic',
    	closeEffect	: 'elastic',
		prevEffect		: 'none',
		nextEffect		: 'none',
		centerOnScroll: 'false',
		showNavArrows: 'true',
		arrows: 'true',	
		scrolling:'yes',
    	tpl: {
			closeBtn : '<a title="Close" class="fancybox-item fancybox-close gallery-close" href="javascript:;"></a>'
		},
		helpers : {		
    		title : {
    			type : 'inside'
    		},
			overlay : {
				css : {
					'background' : 'rgba(58, 42, 45, 0.30)'
				}
			}
    	}
		});

    $("iframe").each(function(){
        var ifr_source = $(this).attr('src');
        var wmode = "wmode=transparent";
        if(ifr_source.indexOf('?') != -1) $(this).attr('src',ifr_source+'&'+wmode);
        else $(this).attr('src',ifr_source+'?'+wmode);
    });

});


$(window).load(function(){
    $('.thanks-gallery ul').carouFredSel({
        prev: '.back',
        next: '.forward',
        items: 4,
        height: 'auto',
        auto: false,
        scroll:{
            items:1,
            duration: 800

        }
    });


    $('.nav-menu').singlePageNav({
        offset: $('.nav-menu').outerHeight(),
        filter: ':not(.external)',
        updateHash: true,
        beforeStart: function() {
        },
        onComplete: function() {
        }
    });
});